package com.atguigu.mycloud.Enum;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author 任浩
 * @version 1.0
 */

@Data
@AllArgsConstructor
public class ReturnMessage<T> {
    private String code;   //返回的码值
    private String message;  //返回的状态信息
    private T data; //返回的数据
    private long timeSteamp; //返回的时间戳。

    public ReturnMessage(){
        timeSteamp  =  System.currentTimeMillis();
    }

    //返回成功的数据的标准格式。
    public static <T> ReturnMessage<T> success(T data){
        ReturnMessage returnMessage = new ReturnMessage();
        returnMessage.setCode(ReturnCodeEnum.RC200.getCode());
        returnMessage.setMessage(ReturnCodeEnum.RC200.getMessage());
        returnMessage.setData(data);

        return returnMessage;
    }

    //返回失败的方法
    public static <T> ReturnMessage fail(String code, String message){
        ReturnMessage returnMessage = new ReturnMessage();
        returnMessage.setCode(code);
        returnMessage.setMessage(message);
        returnMessage.setData(null);

        return returnMessage;
    }
}
